package com.example.springbootsfzy.controller.sunkaixuan;


import com.example.springbootsfzy.domain.Audios;
import com.example.springbootsfzy.service.sunkaixuan.AudioService;
import com.example.springbootsfzy.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("Audio")
@CrossOrigin
public class AudioController {

    @Autowired
    private AudioService audioService;

    @GetMapping("/selectAll")
    @ResponseBody
    public R selectAll() {
        return R.ok(audioService.selectAll());
    }

    @GetMapping("/selectByConsultantId/{id}")
    @ResponseBody
    public R selectByPrimaryKey(@PathVariable int id) {
        return R.ok(audioService.selectByPrimaryKey(id));
    }

    @PostMapping
    @ResponseBody
    public R insertSelective(@RequestBody Audios record){
        int i = audioService.insertSelective(record);
        if (i > 0) {
            return R.ok("添加成功");
        }else {
            return R.error("添加失败");
        }
    }

    @PutMapping("/update")
    @ResponseBody
    public R updateByPrimaryKeySelective(@RequestBody Audios record){
        int i = audioService.updateByPrimaryKeySelective(record);
        if (i > 0) {
            return R.ok("修改成功");
        }else {
            return R.error("修改失败");
        }
    }

    @DeleteMapping("/delete/{audioId}")
    @ResponseBody
    public R deleteByPrimaryKey(@PathVariable int audioId) {
        int i = audioService.deleteByPrimaryKey(audioId);
        if (i > 0) {
            return R.ok("删除成功");
        }else {
            return R.error("删除失败");
        }
    }
}